﻿using System;
using System.Collections.Generic;
using System.Web;

namespace Htmlx
{
    public class PageMethodModule : IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpContext context = HttpContext.Current;
            if (context.Request.RawUrl.Contains(".htmlx/"))
            {
                string trueUrl = context.Request.RawUrl.Substring(0, context.Request.RawUrl.LastIndexOf(".htmlx/") + 6);
                context.RewritePath(trueUrl, context.Request.RawUrl.Substring(trueUrl.Length), context.Request.QueryString.ToString());
            }
        }

        #endregion
    }
}
